package com.jdrx.sw.sewage.remote;

import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;

import com.jdrx.platform.commons.rest.beans.enums.EApiStatus;
import com.jdrx.platform.commons.rest.beans.vo.ResposeVO;
import com.jdrx.platform.commons.rest.exception.BizException;

/**
 * 解析dubbo远程调用返回数据
 */
public class RemoteUtil {
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static void parseReturnData(Object callback) throws Exception {
		ResposeVO resposeVO = new ResposeVO();
		if (callback instanceof Map) {
			BeanUtils.populate(resposeVO, (Map) callback);
		} else {
			resposeVO = (ResposeVO) callback;
		}
		
		if(!StringUtils.equals(resposeVO.getStatus(), EApiStatus.SUCCESS.getStatus())) {
			throw new BizException(resposeVO.getMessage());
		}
	}
}